package com.search_wheel.config;

import jakarta.annotation.PostConstruct;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "ai.zhipu")
public class AiConfig {
    private String apiKey;
    private String baseUrl;
    private String model;
    private int timeout;
    private boolean enabled;

    @PostConstruct
    public void validateConfig() {
        System.out.println("=== AI配置验证 ===");
        System.out.println("enabled: " + enabled);
        System.out.println("apiKey: " + (apiKey != null ? apiKey.substring(0, Math.min(8, apiKey.length())) + "..." : "null"));
        System.out.println("baseUrl: " + baseUrl);
        System.out.println("model: " + model);
        System.out.println("timeout: " + timeout);

        if (enabled && (apiKey == null || apiKey.trim().isEmpty())) {
            System.err.println("WARNING: AI服务已启用但API Key为空！");
        }

        if (enabled && (baseUrl == null || baseUrl.trim().isEmpty())) {
            System.err.println("WARNING: AI服务已启用但Base URL为空！");
        }
    }

    public String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }
}
